<template>
	<view :style="type=='view'?'padding-bottom:30rpx':''" class="content">
		<LoadingTips v-if="showLoading" :imageUrl="imageUrl" :type="0"></LoadingTips>
		<block v-if="!type">
			<view @click="navigate('/page_other/resume/personal_information')" class="block info-block">
				<view class="info">
					<view class="name">{{information.name}}
						<text class="iconfont icon-bianjishuru"></text>
					</view>
					<view class="other-item">
						<view class="other" v-if="information.workTime!=='工作0年'">
							{{information.workTime}}·
						</view>
						<view class="other" v-if="information.workTime==='工作0年'">经验小于1年 · </view>
						<view class="other">{{information.birthday}} · </view>
						<view class="other">{{information.education}}</view>
					</view>
				</view>
				<image :src="information.faceUrl" class="user-photo"></image>
			</view>
			<view class="block intention">
				<view class="block-info">
					<view class="block-name">求职意向</view>
					<view style="font-size: 26rpx;font-weight: bold;flex-grow: 10;color: red;">（必填）</view>
					<view @click="navigate('/page_other/resume/career_intention')">
						<view class="add-btn iconfont icon-jiahao"></view>
					</view>
				</view>
				<view class="block-content" v-for="(item,index) in intention" :key="item.id">
					<Del :item="item" :data_transit="{ index: index, item: item }" @delItem="deleteRow(1,item.id)">
						<view @click="navigate('/page_other/resume/career_intention?id='+item.id)" class="article-item">
							<view class="editItem">
								<view class="flex-box">
									<view class="title">{{item.postName}}</view>
									<view class="iconfont icon-gengduo1 arrow"></view>
								</view>
								<view class="fs12 darkgray mt20">{{item.regCity}}{{item.regArea}} ·
									{{item.salaryMin}}-{{item.salaryMax}}元
								</view>
							</view>
						</view>
					</Del>
				</view>
			</view>
			<view hover-class="none" class="block intention">
				<view class="block-info">
					<view class="block-name">工作经历</view>
					<view style="font-size: 26rpx;font-weight: bold;flex-grow: 10;color: #1b00ff;">（选填）</view>
					<view @click="navigate('/page_other/resume/work_experience')">
						<view class="add-btn iconfont icon-jiahao"></view>
					</view>
				</view>
				<view class="block-content" v-for="(item,index) in workExperience" :key="item.id">
					<Del :item="item" :data_transit="{ index: index, item: item }" @delItem="deleteRow(2,item.id)">
						<view @click="navigate('/page_other/resume/work_experience?id='+item.id)" class="article-item">
							<view class="flex-box">
								<view class="title">{{item.companyName}}</view>
								<view class="iconfont icon-gengduo1 arrow"></view>
							</view>
							<view class="fs12 darkgray mt20">{{item.workTimeStart}} 至 {{item.workTimeEnd}}</view>
							<view class="fs12 darkgray mt20">{{item.postName}}</view>
							<view class="fs12 darkgray mt20" style="white-space: pre-wrap;">{{item.duty}}</view>
						</view>
					</Del>
				</view>
			</view>
			<view hover-class="none" class="block intention">
				<view class="block-info">
					<view class="block-name">项目经历</view>
					<view style="font-size: 26rpx;font-weight: bold;flex-grow: 10;color: #1b00ff;">（选填）</view>
					<view @click="navigate('/page_other/resume/project_experience')">
						<view class="add-btn iconfont icon-jiahao"></view>
					</view>
				</view>
				<view class="block-content" v-for="(item,index) in projectExperience" :key="item.id">
					<Del :item="item" :data_transit="{ index: index, item: item }" @delItem="deleteRow(3,item.id)">
						<view @click="navigate('/page_other/resume/project_experience?id='+item.id)"
							class="article-item">
							<view class="flex-box">
								<view class="title">{{item.itemName}}</view>
								<view class="iconfont icon-gengduo1 arrow"></view>
							</view>
							<view class="fs12 darkgray mt20">{{item.startTime}} 至 {{item.endTime}}</view>
							<view class="fs12 mt20" style="white-space: pre-wrap;">{{item.itemContent}}</view>
						</view>
					</Del>
				</view>
			</view>
			<view hover-class="none" class="block intention">
				<view class="block-info">
					<view class="block-name">教育经历</view>
					<view style="font-size: 26rpx;font-weight: bold;flex-grow: 10;color: #1b00ff;">（选填）</view>
					<view @click="navigate('/page_other/resume/education_experience')">
						<view class="add-btn iconfont icon-jiahao"></view>
					</view>
				</view>
				<view class="block-content" v-for="(item,index) in education" :key="item.id">
					<Del :item="item" :data_transit="{ index: index, item: item }" @delItem="deleteRow(4,item.id)">
						<view @click="navigate('/page_other/resume/education_experience?id='+item.id)"
							class="article-item">
							<view class="education-item">
								<view class="education">
									<view class="name">{{item.schoolName}}</view>
									<view class="major">{{item.educationText}}·{{item.major}}</view>
									<view class="major">{{item.startTime}} 至 {{item.endTime}}</view>
								</view>
								<view class="iconfont icon-gengduo1 arrow"></view>
							</view>
						</view>
					</Del>
				</view>
			</view>
			<view hover-class="none" class="block intention">
				<view class="block-info">
					<view class="block-name">语言能力</view>
					<view style="font-size: 26rpx;font-weight: bold;flex-grow: 10;color: #1b00ff;">（选填）</view>
					<view @click="navigate('/page_other/resume/linguistic_competence')">
						<view class="add-btn iconfont icon-jiahao"></view>
					</view>
				</view>
				<view class="block-content" v-for="(item,index) in language" :key="item.id">
					<Del :item="item" :data_transit="{ index: index, item: item }" @delItem="deleteRow(5,item.id)">
						<view @click="navigate('/page_other/resume/linguistic_competence?id='+item.id)"
							class="article-item">
							<view class="language-item">
								<view class="name">{{item.languagesText}}</view>
								<view class="info">{{item.cert}} · {{item.redAndWrtText}}</view>
								<view class="iconfont icon-gengduo1 arrow"></view>
							</view>
						</view>
					</Del>
				</view>
			</view>
			<view @click="navigate('/page_other/resume/extras')" class="block intention">
				<view class="block-info">
					<view class="block-name">优势亮点</view>
					<view style="font-size: 26rpx;font-weight: bold;flex-grow: 10;color: #1b00ff;">（选填）</view>
					<view class="iconfont icon-gengduo1 arrow"></view>
				</view>
				<view class="block-content fs15">
					{{addition}}
				</view>
			</view>
			<view class="btn-block">
				<view @click="createResume" class="btn">一键生成简历</view>
			</view>
		</block>
		<block v-if="type=='view'">
			<view class="block info-block">
				<view class="info">
					<view class="infomation-item">
						<view class="name">{{information.realName}}</view>
						<view class="attention" v-if="information.lookType===2" @click="addLookMe">关注</view>
						<view class="attention1" v-if="information.lookType===1" @click="insertLookMe">已关注</view>
						<view class="resume" @click="dialogue">立即沟通
						</view>
						<view class="resume" @click="callPhone">拨打电话
						</view>
					</view>
					<view class="other-item">
						<view class="other" v-if="information.workTime!=='工作0年'">
							{{information.workTime}} ·
						</view>
						<view class="other" v-if="information.workTime=='工作0年'">经验小于1年 · </view>
						<view class="other">{{information.birthday}} · </view>
						<view class="other">{{information.education}}</view>
					</view>
				</view>
				<image :src="information.faceUrl?information.faceUrl:imageUrl+'/job_hunting/edit_resume/photo.png'"
					class="user-photo"></image>
			</view>
			<view class="block intention">
				<view class="block-info">
					<view class="block-name">求职意向</view>
				</view>
				<view class="block-content" v-for="(item,index) in intention" :key="item.id">
					<view class="flex-box">
						<view class="title">{{item.postName}}</view>
					</view>
					<view class="fs12 darkgray mt20">酒泉 · {{item.salaryMin}}元-{{item.salaryMax}}元</view>
					<view class="label-block">
						<view class="label-item mb20 mr20">全部行业</view>
					</view>
				</view>
			</view>
			<view class="block intention">
				<view class="block-info">
					<view class="block-name">工作经历</view>
				</view>
				<view class="block-content" v-for="(item,index) in workExperience" :key="item.id">
					<view class="flex-box">
						<view class="title">{{item.companyName}}</view>
					</view>
					<view class="fs12 darkgray mt20">{{item.workTimeStart}} 至 {{item.workTimeEnd}}</view>
					<view class="fs12 darkgray mt20">{{item.postName}}</view>
					<view class="fs12 darkgray mt20" style="white-space: pre-wrap;">{{item.duty}}</view>
				</view>
			</view>
			<view class="block intention">
				<view class="block-info">
					<view class="block-name">项目经历</view>
				</view>
				<view class="block-content" v-for="(item,index) in projectExperience" :key="item.id">
					<view class="flex-box">
						<view class="title">{{item.itemName}}</view>
					</view>
					<view class="fs12 darkgray mt20">{{item.startTime}} 至 {{item.endTime}}</view>
					<view class="fs12 mt20" style="white-space: pre-wrap;">{{item.itemContent}}</view>
				</view>
			</view>
			<view class="block intention" style="padding-bottom: 0;">
				<view class="block-info">
					<view class="block-name">教育经历</view>
				</view>
				<view class="block-content" v-for="(item,index) in education" :key="item.id">
					<view class="education-item">
						<view class="education">
							<view class="name">{{item.schoolName}}</view>
							<view class="major">{{item.educationText}}·{{item.major}}</view>
							<view class="major">{{item.startTime}} 至 {{item.endTime}}</view>
						</view>
					</view>
				</view>
			</view>
			<view class="block intention">
				<view class="block-info">
					<view class="block-name">语言能力</view>
				</view>
				<view class="block-content" v-for="(item,index) in language" :key="item.id">
					<view class="language-item">
						<view class="name">{{item.languagesText}}</view>
						<view class="info">{{item.cert}} · {{item.redAndWrtText}}</view>
					</view>
				</view>
			</view>
			<view class="block intention">
				<view class="block-info">
					<view class="block-name">优势亮点</view>
				</view>
				<view class="block-content fs15">
					{{addition}}
				</view>
			</view>
		</block>
		<SuccessDialog v-if="showDialog" cancelText="查看我关注的人" confirmText="继续找人才" @callback="dialogCallback">
			<slot style="display: flex;flex-direction: column;">
				<image src="/static/tabbar/3adf1ae20d1e3f45cc08c75cbf181b1.png" style="width: 150rpx;height: 150rpx;">
				</image>
				<view>关注成功！</view>
			</slot>
		</SuccessDialog>
	</view>
</template>

<script>
	import {
		sendHiMessage,
		getToAccount
	} from '@/util/im.js';
	import Del from '@/page_other/components/AyOperate/Del'
	import SuccessDialog from '@/page_other/components/SuccessDialog/SuccessDialog.vue';
	import {
		getInformation as getInformationApi,
		getIntentionList as getIntentionListApi,
		getWorkExpList as getWorkExpListApi,
		getProjectExpList as getProjectExpListApi,
		getEducationList as getEducationListApi,
		getLanguageList,
		getAddition as getAdditionApi,
		delIntention,
		delWorkExp,
		delProjectExp,
		delEducation,
		delLanguage,
		getResumePdf
	} from '@/api/resume.js';
	import {
		insertLookMe
	} from '@/api/job_hunting.js'
	import {
		doOperationRecordsApi
	} from '@/api/job_hunting.js'
	export default {
		components: {
			Del,
			SuccessDialog
		},
		data() {
			return {
				showDialog: false,
				imageUrl: '',
				type: '',
				cId: 0,
				loading: false,
				information: {
					realName: '',
					workTime: '',
					birthday: '',
					education: '',
					faceUrl: ''
				},
				intention: [],
				workExperience: [],
				projectExperience: [],
				education: [],
				language: [],
				addition: '',
				showLoading: false,
			}
		},
		watch: {
			loading: {
				handler(val) {
					if (val) {
						uni.showLoading({
							title: '加载中',
							mask: true
						})
					} else {
						uni.hideLoading()
					}
				},
				immediate: true
			}
		},
		methods: {
			//onShareAppMessage 分享给朋友
			//onShareTimeline  分享到朋友圈
			// #ifdef MP
			onShareAppMessage: function(res) {
				this.getCount(4)
				if (res.from === 'button') {
					// 来自页面内转发按钮
					console.log(res.target)
				}
				return {
					title: this.list.jobTitle,
					path: '/page_other/resume/index?id=' + this.cId + '&type=' +
						view,
				}
			},
			// #endif
			onShareTimeline(res) {
				let distSource = uni.getStorageSync('distSource');
				this.getCount(4)
				if (distSource) {
					return {
						title: this.list.jobTitle,
						path: '/page_other/resume/index?id=' + this.cId + '&type=' +
							view,
						type: 0,
						query: 'id=' + distSource,
					}
				}
			},
			dialogCallback(e) {
				console.log(e);
				if (e) {
					this.showDialog = false;
				} else {
					uni.navigateTo({
						url: '/page_other/attention/attention?type=' + 2
					})
					this.showDialog = false;
				}
			},
			dialogue() {
				uni.$on('chooseChatPosition', (e) => {
					uni.$off('chooseChatPosition');
					uni.showLoading({
						title: '发送中',
						mask: true
					})
					try {
						sendHiMessage('你好，请问近期在看新的工作机会吗？', this.information.telPhone, e).finally(() => {
							uni.hideLoading()
							this.showToast('发送成功')
						})
					} catch (e) {
						uni.hideLoading()
					}
				})
				uni.navigateTo({
					url: '/page_other/choose_position/choose_position'
				})
			},
			callPhone() {
				if (this.isLogin()) {
					let para = {
						cancelText: '我再想想',
						success: (confirm) => {
							if (confirm.confirm) {
								uni.makePhoneCall({
									phoneNumber: this.information.telPhone,
									success() {
										console.log('拨打成功了');
									},
									fail() {
										console.log('拨打失败了');
									}
								})
								this.getCount(5)
							}
						}
					}
					para.title = '确认拨打';
					para.content = '平台严禁用人单位做出任何损害求职者合法权益的违法违规行为，包括但不限于扣押求职者证件、收取求职者财物、向求职者集资、让求职者入股等。'
					para.confirmText = '拨打';
					uni.showModal(para);
				}

			},
			getCount(type) {
				uni.showLoading({
					title: '加载中'
				})
				doOperationRecordsApi({
					type: type,
				}).then((res) => {
					console.log(res)
				}).catch(() => {
					console.log(res)
				})
			},
			isLogin() {
				if (!this.user) {
					uni.showModal({
						title: '提示',
						content: '需要先登录！',
						cancelText: '先逛逛',
						confirmText: '去登录',
						success(res) {
							if (res.confirm) {
								uni.switchTab({
									url: '/pages/mine/index'
								})
							} else {

							}
						}
					})
					return false;
				} else {
					return true;
				}
			},
			createResume() {
				this.showLoading = true
				setTimeout(() => {
					getResumePdf({}).then((res) => {
						uni.downloadFile({
							url: res,
							success: (e) => {
								uni.openDocument({
									filePath: e.tempFilePath,
									fileType: 'pdf',
									success: () => {
										this.showLoading = false
									},
									fail: () => {
										this.showLoading = false
										this.showToast('生成失败！')
									},
								})
							},
							fail: (e) => {
								this.showLoading = false
								this.showToast('下载失败！')
							}
						})
					}).finally(() => {
						this.showLoading = false
					})
				}, 2000)
			},
			deleteRow(type, id) {
				uni.showModal({
					title: '提示',
					content: '确定删除该数据吗',
					success: (e) => {
						if (e.confirm) {
							let promise = null;
							uni.showLoading({
								title: '删除中',
								mask: true
							})
							switch (type) {
								case 1:
									promise = delIntention({
										id
									});
									break;
								case 2:
									promise = delWorkExp({
										id
									});
									break;
								case 3:
									promise = delProjectExp({
										id
									});
									break;
								case 4:
									promise = delEducation({
										id
									});
									break;
								case 5:
									promise = delLanguage({
										id
									});
									break;
							}
							promise.then(() => {
								this.showToast('删除成功')
								this.refresh(type);
							})
						}
					}
				})
			},
			refresh(type) {
				switch (type) {
					case 0:
						this.getInformation();
						break
					case 1:
						this.getIntention();
						break;
					case 2:
						this.getWorkExp();
						break;
					case 3:
						this.getProjectExp();
						break;
					case 4:
						this.getEducation();
						break;
					case 5:
						this.getLanguage();
						break;
					case 6:
						this.getAddition();
						break;
				}
				this.$store.dispatch('user/getUser');
			},
			navigate(url) {
				uni.navigateTo({
					url
				})
			},
			getInformation() {
				return getInformationApi({
					id: this.cId
				}).then((res) => {
					this.information = res;
				})
			},
			getIntention() {
				return getIntentionListApi({
					id: this.cId
				}).then((res) => {
					this.intention = res ?? [];
				})
			},
			getWorkExp() {
				return getWorkExpListApi({
					id: this.cId
				}).then((res) => {
					this.workExperience = res ?? [];
				})
			},
			getProjectExp() {
				return getProjectExpListApi({
					id: this.cId
				}).then((res) => {
					this.projectExperience = res ?? [];
				})
			},
			getEducation() {
				return getEducationListApi({
					customerId: this.cId
				}).then((res) => {
					this.education = res ?? [];
				})
			},
			getLanguage() {
				return getLanguageList({
					id: this.cId
				}).then((res) => {
					this.language = res ?? [];
				})
			},
			getAddition() {
				return getAdditionApi({
					id: this.cId
				}).then((res) => {
					this.addition = res?.data ?? '';
				})
			},
			addLookMe() {
				uni.showLoading({
					title: '关注中'
				})
				insertLookMe({
					cid: this.cId,
					userType: 2,
					lookMeType: 2,
					state: 2
				}).then((res) => {
					uni.hideLoading();
					this.showDialog = true;
					this.getInformation();
				})
			},
			insertLookMe() {
				uni.showLoading({
					title: '取消关注中'
				})
				insertLookMe({
					cid: this.cId,
					userType: 2,
					lookMeType: 2,
					state: 1
				}).then((res) => {
					uni.hideLoading();
					this.showToast('取消关注成功');
					this.getInformation();
				})
			},
			lookMe() {
				insertLookMe({
					cid: this.cId,
					userType: 2,
					lookMeType: 1,
					state: 2
				})
			},
		},
		computed: {
			user() {
				return this.$store.getters.user
			}
		},
		onLoad(e) {


			this.type = e.type; //自己访问还是别人查看
			if (this.type == 'view') {
				this.cId = e.id;
				uni.setNavigationBarTitle({
					title: '人力资源信息'
				})
			}
			this.imageUrl = this.globalConfig.imageUrl;
			this.$nextTick(() => {
				this.loading = true
				Promise.all([this.getInformation(), this.getIntention(), this.getWorkExp(), this.getProjectExp(),
					this
					.getEducation(), this.getLanguage(), this.getAddition()
				]).finally(() => {
					this.loading = false
				})
			})
			uni.$on('refresh', (type) => {
				this.refresh(type)
			})
		}
	}
</script>

<style lang="scss">
	page {
		background: #FAFAFA;
	}

	.content {
		width: 100%;
		padding: 30rpx;
		padding-bottom: 110rpx;

		.block {
			width: 100%;
			background: #fff;
			box-shadow: 0 0 10px 0 #efefef;
			border-radius: 10rpx;
			margin-bottom: 30rpx;
			padding: 40rpx 30rpx;
			color: #313131;

			.arrow {
				font-size: 24rpx;
				text-align: right;
				flex-grow: 0;
				color: #999;
			}
		}

		.block.info-block {
			display: flex;
			flex-direction: row;
			align-items: center;

			.user-photo {
				width: 130rpx;
				height: 130rpx;
				background: #efefef;
				border-radius: 50%;
				margin-right: 20rpx;
				position: relative;
			}

			.info {
				flex-grow: 1;

				.name {
					font-size: 40rpx;
					font-weight: bold;

					.iconfont {
						font-size: 30rpx;
						font-weight: normal;
						margin-left: 16rpx;
					}
				}

				.infomation-item {
					display: flex;
					flex-direction: row;
					align-items: center;

					.name {
						font-size: 40rpx;
						font-weight: bold;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
						width: 140rpx;

						.iconfont {
							font-size: 30rpx;
							font-weight: normal;
							margin-left: 16rpx;
						}
					}

					.attention {
						width: 110rpx;
						height: 45rpx;
						background: #FF7626;
						color: #fff;
						border-radius: 20rpx;
						text-align: center;
						font-size: 28rpx;
						padding-top: 1rpx;
						margin-left: 15rpx;
					}

					.attention1 {
						width: 120rpx;
						height: 45rpx;
						background: none;
						color: #FF7626;
						border: 2rpx solid #FF7626;
						border-radius: 20rpx;
						text-align: center;
						font-size: 28rpx;
						margin-left: 15rpx;
						padding-top: 1rpx;

					}

					.resume {
						font-size: 28rpx;
						width: 140rpx;
						border-radius: 20rpx;
						text-align: center;
						padding-top: 2rpx;
						border: 1px solid #FF7626;
						color: #FF7626;
						margin-left: 10rpx;
					}
				}

				.other-item {
					display: flex;
					flex-direction: row;
					align-items: center;

					.other {
						font-size: 26rpx;
						margin-top: 15rpx;
						color: #000;
					}
				}
			}

			.user-photo {
				width: 120rpx;
				height: 120rpx;
				border-radius: 50%;
				margin-left: 20rpx;
				flex-grow: 0;
			}
		}

		.block.intention {
			display: flex;
			flex-direction: column;

			.block-info {
				display: flex;
				flex-direction: row;
				align-items: center;

				.block-name {
					font-size: 40rpx;
					font-weight: bold;
					flex-grow: 1;
				}

				.add-btn {
					width: 60rpx;
					height: 60rpx;
					background: #F6F7F9;
					display: flex;
					align-items: center;
					justify-content: center;
					border-radius: 50%;
					font-size: 30rpx;
					font-weight: bold;
					flex-grow: 0;
				}
			}

			.block-content {
				display: flex;
				flex-direction: column;
				margin-top: 20rpx;

				.flex-box {
					display: flex;
					//flex-direction: row;
					align-items: center;

					.title {
						flex-grow: 1;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
						font-weight: bold;
					}

					.time {
						width: 345rpx;
						font-size: 26rpx;
						color: #999;
						text-align: right;
					}
				}

				.time {
					width: 345rpx;
					font-size: 26rpx;
					color: #999;
					text-align: right;
				}

				.label-block {
					margin-top: 20rpx;
					display: flex;
					flex-direction: row;
					flex-wrap: wrap;

					.label-item {
						font-size: 26rpx;
						background: #F7F8FC;
						padding: 12rpx 20rpx;
						border-radius: 10rpx;
					}
				}

				.education-item {
					border-bottom: 1px solid #efefef;
					display: flex;
					flex-direction: row;
					padding: 20rpx 0;

					.education {
						display: flex;
						flex-direction: column;
						justify-content: center;
						flex-grow: 1;
						width: 100%;

						.name {
							margin-top: -20rpx;
							font-size: 34rpx;
							font-weight: bold;
						}

						.major,
						.time {
							font-size: 28rpx;
							color: #999;
							margin-top: 20rpx;
							width: 400rpx;
						}
					}
				}

				.education-item:last-child {
					border: none;
				}

				.language-item {
					display: flex;
					flex-direction: row;
					align-items: center;

					.name {
						flex-grow: 1;
						font-size: 28rpx;
						font-weight: bold;
					}

					.info {
						flex-grow: 0;
						font-size: 28rpx;
						font-weight: bold;
						text-align: right;
					}
				}

				.language-item:last-child {
					border: none
				}
			}
		}

		.block:last-child {
			margin: 0;
		}

		.btn-block {
			position: fixed;
			width: 100%;
			bottom: 0;
			left: 0;
			background: #fff;
			height: 110rpx;
			box-shadow: 0px -5px 10px #efefef;
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: center;
			z-index: 9999;

			.btn {
				color: #FF7626;
				border: 1px solid #FF7626;
				border-radius: 40rpx;
				padding: 10rpx 40rpx;
				font-size: 28rpx;
				display: flex;
				justify-content: center;
				align-items: center;
			}
		}
	}
</style>